package com.leonzhangxf.web.util.feign;

import com.leonzhangxf.web.util.feign.api.github.GitHub;
import com.leonzhangxf.web.util.feign.api.github.bean.Contributor;
import com.leonzhangxf.web.util.feign.api.github.bean.Repo;
import feign.Feign;
import feign.gson.GsonDecoder;

import java.util.List;

/**
 * A demonstrate for feign.
 * <p>
 * https://github.com/OpenFeign/feign
 *
 * <p>
 * Feign 特性或扩展列表：
 *
 * <p>
 * Basic:
 * <ol>
 * <li>Decoders</li>
 * <li>Encoders</li>
 * <li>@Body templates</li>
 * <li>Headers</li>
 * </ol>
 *
 * <p>
 * Integrations:
 * <ol>
 * <li>Gson</li>
 * <li>Jackson</li>
 * <li>Sax</li>
 * <li>JAXB</li>
 * <li>JAX-RS</li>
 * <li>OkHttp</li>
 * <li>Ribbon</li>
 * <li>Java 11 Http2</li>
 * <li>Hystrix</li>
 * <li>SOAP</li>
 * <li>SLF4J</li>
 * </ol>
 *
 * <p>
 * Advanced usage:
 * <ol>
 * <li>Base Apis(single-inheritance)</li>
 * <li>Logging</li>
 * <li>Request Interceptors</li>
 * <li>Custom @Param Expansion</li>
 * <li>Dynamic Query Parameters</li>
 * <li>Retry</li>
 * <li>Static and Default Methods</li>
 * </ol>
 *
 * @author leonzhangxf
 * @date 20190429
 */
public class FeignStarter {

    public static void main(String[] args) {
        GitHub gitHub = GitHub.getInstance();

        List<Repo> repoList = gitHub.reposSortByFullName("leonzhangxf");
        repoList.forEach(System.out::println);
        System.out.println("==================");

        List<Contributor> contributorList = gitHub.contributorsOfReposOfOwner("leonzhangxf");
        contributorList.forEach(System.out::println);
    }

    private static void primaryDemo() {
        GitHub github = Feign.builder()
            .decoder(new GsonDecoder())
            .target(GitHub.class, "https://api.github.com");

        // Fetch and print a list of the contributors to this library.
        List<Contributor> contributors = github.contributors("OpenFeign", "feign");
        for (Contributor contributor : contributors) {
            System.out.println(contributor.toString());
        }
    }
}